<?php
namespace Home\Controller;
	use Think\Controller;
	class FolderController extends Controller{
		protected $userId;
		
		protected function isAuthorize(){
               $loginStatus=session('loginStatus');
               if(!$loginStatus){
                  $this->redirect('User/userLogin','',2,'not authirize');
                  exit();
                }
               $this->userId=session('id');
               $userName=session('email');
               $this->assign('userName',$userName);
               $this->assign('userId',$this->userId);			
			
		}
		
		public function addFolder(){
		   $this->isAuthorize();
		   if(empty($_POST)){
			   $this->display('addFolder');
			   return false;
		   }
		   $folderObj= new \Home\Model\FolderModel();
		   $status=$folderObj->addFolder($this->userId,$_POST);
		   if($status==false){
			  echo $folderObj->lastErrorMessage;
			  return false;
		   }
		   $this->redirect('manager/index','',2,'add folder ok');

	   }
	    
	   
	   public function  renameFolderName($folderId){
		   $this->isAuthorize();
		   $folderObj= new \Home\Model\FolderModel();
		   $status=$folderObj->findFolderNameByFolderId($folderId);
		   if($status == false){
			  echo $folderObj->lastErrorMessage;
			  return $status;
		   }
		   $affectRow=$folderObj->renameFolderName($this->userId,$folderId,$_POST);
		    if($affectRow==false){
			   $status=array('status'=>false,'message'=>'更新失败');
			   $this->ajaxReturn($status);
			   return false;
		   }
		   $status=array('status'=>true,'message'=>'更新成功');
		   $this->ajaxReturn($status);
		   
	   }
	   
	   public function getFolderList($page=0){
		   $this->isAuthorize();
		   $folderObj= new \Home\Model\FolderModel();
		   $folderList=$folderObj->findFolderByOwenerId($this->userId);
		   if($folderList===false){
			   echo '查询错误';
		   }
		   $this->assign('dataList',$folderList);
		   $this->display('FolderList');
	   }
	   
	   public function deleteFolder($folderId){
		   $this->isAuthorize();
		   $folderObj= new \Home\Model\FolderModel();
		   $affectRow=$folderObj->deleteFolder($this->userId,$folderId);
		   if($affectRow==false){
			   $status=array('status'=>false,'message'=>'删除失败');
			   $this->ajaxReturn($status);
			   return false;
		   }
		   $status=array('status'=>true,'message'=>'删除成功');
		   $this->ajaxReturn($status);
	   }
	}
	   
	  
	   